<?php

/**
 *
 * @version $Id:$
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */

require_once(t3lib_extMgm::extPath('attac_div').'class.tx_attacdiv.php');
require_once(t3lib_extMgm::extPath('attac_movedb').'class.tx_attacmovedb.php');

class Tx_Joinformattac_Controller_JoinFormController extends Tx_Extbase_MVC_Controller_ActionController{
	/**
	 * @var Tx_Joinformattac_Domain_Repository_JoinFormRepository
	 * 
	 */
	
	protected $joinFormRepository;
	/**
	 * 
	 * @var Tx_Joinformattac_Domain_Model_JoinForm
	 */
	protected $test;

	/*
	 * @var int
	 */
	protected $uid;
	
	/**
	 * 
	 * @param Tx_Joinformattac_Domain_Repository_JoinFormRepository $joinFormRepository
	 * @return void
	 */
	
	
	public function injectJoinFromRepository(Tx_Joinformattac_Domain_Repository_JoinFormRepository $joinFormRepository){
		$this->joinFormRepository = $joinFormRepository;
		
		
	}
	/**
	 * Index action for this controller. 
	 * @param Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm A fresh JoinForm object taken as a basis for the rendering
	 * @return string An HTML form for creating a new JoinForm
	 * @dontvalidate $newJoinForm
	 */
	public function indexAction(Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm = NULL) {	

		$bla = $this->settings['itemName'];
		t3lib_div::debug($bla);
		//initFlex();
		//********************************
		$this->test = t3lib_div::makeInstance("Tx_Joinformattac_Domain_Model_JoinForm");
		$this->test->setVorname("Franz");
		$this->test->setNachname("Wurst");
		$this->test->setStrasse("ajcvstr. 12");
		$this->test->setPlz("12345");
		$this->test->setOrt("orrtt");
		$this->test->setLand("Landia");
		$this->test->setBeitrag("5");
		$this->test->setZahlungsrhythmus("vierteljährlich");
		$this->test->setAnrede("Herr");
		$this->test->setBeruf("Klmepner");	
		$this->test->setGeburtstag("1974-11-11");
		$this->test->setTelefon("12339128791");
		$this->test->setFax("127618276");
		$this->test->setEmail("miguel@socio1.de");
		$this->test->setDatenweitergabe(TRUE);
		$this->test->setBemerkungen("Das ist eine Bemerkung!");
		$this->test->setEinzug(TRUE);
		$this->test->setKontonummer("123297998");
		$this->test->setBlz("50050201");
		$this->test->setKontovorname("Hans");
		$this->test->setKontonachname("Wurst");
		//$newJoinForm = $this->test;
		//t3lib_div::debug($this->test);
		//$this->joinFormRepository->add($this->test); 
		//**********************************/
		//$newJoinForm = $this->test;
		$this->view->assign('newJoinForm', $this->test);
	}
	/**
	 * serves to confirm the input by the user
	 *
	 * @param Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm A fresh JoinForm object which has not yet been added to the repository
	 * @return string
	 */
	public function confirmAction(Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm) {
//		$this->test = $newJoinForm;
		
		$this->view->assign('newJoinForm', $newJoinForm);
	}
	/**
	 * 
	 * Enter description here ...
	 * @param Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm
	 * @return void
	 */
	public function becomeAction(Tx_Joinformattac_Domain_Model_JoinForm $newJoinForm){
		$blz = $newJoinForm->getBlz();
		$this->joinFormRepository->add($newJoinForm);
		//$arr = array("foo" => "bar", 12 => true);
		$arr = 'Geil';
		tx_attacdiv::writeFile('/var/www/test1/attac/htdocs/fileadmin/MOVEDB/test.sql', $arr, FILE_APPEND);
		//if(0 === file_put_contents("/var/www/test1/attac/htdocs/fileadmin/MOVEDB/test.sql", $arr, FILE_APPEND | LOCK)){
		//$this->flashMessages->add('Lieber_r '.$newJoinForm->getVorname().', hier ging leider etwas schief...');
			/*$param = array('type' => 'file could not be written',
		     'error' => 'the file "'.$path.'" could not be written',
		     'datetime' => time(),
		     'page' => $GLOBALS['TSFE']->id,
		     'element' => $this->oParent->cObj->currentRecord,
		     'user' => $GLOBALS['TSFE']->fe_user->user['uid'],
		     );
      		tx_attacdiv::_notifyAdmin($param);*/
	//}
	$this->flashMessages->add('Lieber_r '.$newJoinForm->getVorname().', willkommen bei attac!');
	}
	public function initFlex(){
    $this->pi_initPIflexForm(); // Init and get the flexform data of the plugin
    $this->lConf = array(); // Setup our storage array...
    // Assign the flexform data to a local variable for easier access
    $piFlexForm = $this->cObj->data['pi_flexform'];
    // Traverse the entire array based on the language...
    // and assign each configuration option to $this->lConf array...
    foreach ( $piFlexForm['data'] as $sheet => $data ) {
        foreach ( $data as $lang => $value ) {
            foreach ( $value as $key => $val ) {
                $this->lConf[$key] = $this->pi_getFFvalue($piFlexForm, $key, $sheet);
            }
        }
    }
	}
}
?>